﻿' Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax

Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols

    ''' <summary>
    ''' Represents a synthesized lambda. 
    ''' </summary>
    Friend Class SynthesizedLambdaSymbol
        Inherits LambdaSymbol

        Private ReadOnly m_isDelegateRelaxationStub As Boolean

        ''' <summary>
        ''' Initializes a new instance of the <see cref="SynthesizedLambdaSymbol" /> class.
        ''' </summary>
        Public Sub New(
            syntaxNode As VisualBasicSyntaxNode,
            parameters As ImmutableArray(Of BoundLambdaParameterSymbol),
            returnType As TypeSymbol,
            binder As Binder,
            isDelegateRelaxationStub As Boolean
        )
            MyBase.New(syntaxNode, Nothing, parameters, returnType, binder)

            m_isDelegateRelaxationStub = isDelegateRelaxationStub
        End Sub

        ''' <summary>
        ''' Gets a value indicating whether the symbol was generated by the compiler
        ''' rather than declared explicitly.
        ''' </summary>
        Public Overrides ReadOnly Property IsImplicitlyDeclared As Boolean
            Get
                Return True
            End Get
        End Property

        Public Overrides ReadOnly Property DeclaringSyntaxReferences As ImmutableArray(Of SyntaxReference)
            Get
                Return ImmutableArray(Of SyntaxReference).Empty
            End Get
        End Property

        Public Overrides Function Equals(obj As Object) As Boolean
            Return obj Is Me
        End Function

        Public Overrides Function GetHashCode() As Integer
            Return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(Me)
        End Function

        Friend Overrides ReadOnly Property GenerateDebugInfoImpl As Boolean
            Get
                ' delegate relaxation stub contains no user code, it only contains a synthesized call to the target method
                Return Not m_isDelegateRelaxationStub
            End Get
        End Property

    End Class
End Namespace
